package com.hb.trans.mvp.presenter

import com.basiclib.base.BasePresenter
import com.basiclib.lifecycle.RxLifecycleUtils
import com.basiclib.network.RetryWithDelay
import com.basiclib.network.RxErrorHandler
import com.hb.trans.bean.Base
import com.hb.trans.global.ErrorHandleSubscriber
import com.hb.trans.mvp.contract.EvaluateCoachContract
import com.hb.trans.mvp.model.EvaluateCoachModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject

class EvaluateCoachPresenter @Inject constructor(model: EvaluateCoachModel, var errorHandler: RxErrorHandler) :
    BasePresenter<EvaluateCoachContract.View, EvaluateCoachContract.Model>(model) {
    fun commitEvaluate(
        stunum: String,
        inscode: String,
        coachName: String,
        coanum: String,
        content: String,
        periodId: String
    ) {
        mModel.commitEvaluate(stunum, inscode, coachName, coanum, content, periodId)
            .subscribeOn(Schedulers.io())
            .retryWhen(RetryWithDelay())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(RxLifecycleUtils.bindToLifecycle(mRootView!!))
            .subscribe(object : ErrorHandleSubscriber<Base<Nothing>>(errorHandler) {
                override fun next(r: Base<Nothing>) {
                    if (r.code == 200) {
                        mRootView?.commitSucess("成功")
                    } else {
                        mRootView?.showShortToast(r.message ?: "")
                    }
                }
            })
    }
}